home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / ios.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  6.0 KB  |  291 lines

  1. #ifndef __IOS_CC
  2. #define __IOS_CC
  3. #pragma option push -b -a4 -Vx- -Ve- -w-inl -w-aus -w-sig
  4.  
  5. /***************************************************************************
  6.  *
  7.  * ios.cc - Definition for the Standard Library iostreams
  8.  *
  9.  * $Id: ios.cc,v 1.51 1996/09/13 23:39:36 smithey Exp $
  10.  *
  11.  ***************************************************************************
  12.  *
  13.  * (c) Copyright 1994, 1995 Rogue Wave Software, Inc.
  14.  * ALL RIGHTS RESERVED *
  15.  * The software and information contained herein are proprietary to, and
  16.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  17.  * intends to preserve as trade secrets such software and information.
  18.  * This software is furnished pursuant to a written license agreement and
  19.  * may be used, copied, transmitted, and stored only in accordance with
  20.  * the terms of such license and with the inclusion of the above copyright
  21.  * notice.  This software and information or any other copies thereof may
  22.  * not be provided or otherwise made available to any other person.
  23.  *
  24.  * Notwithstanding any other lease or license that may pertain to, or
  25.  * accompany the delivery of, this computer software and information, the
  26.  * rights of the Government regarding its use, reproduction and disclosure
  27.  * are as set forth in Section 52.227-19 of the FARS Computer
  28.  * Software-Restricted Rights clause.
  29.  * 
  30.  * Use, duplication, or disclosure by the Government is subject to
  31.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  32.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  33.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  34.  * P.O. Box 2328, Corvallis, Oregon 97339.
  35.  *
  36.  * This computer software and information is distributed with "restricted
  37.  * rights."  Use, duplication or disclosure is subject to restrictions as
  38.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  39.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  40.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  41.  * then the "Alternate III" clause applies.
  42.  *
  43.  **************************************************************************/
  44.  
  45. #include <streambuf>
  46. #include <iosfwd>
  47.  
  48.  
  49. #ifndef _RWSTD_NO_NAMESPACE
  50. namespace std { 
  51. #endif
  52.   
  53. extern istream _RWSTDExport cin;
  54.  
  55. #ifndef _RWSTD_NO_WIDE_CHAR
  56. extern wistream _RWSTDExport wcin;
  57. #endif
  58.  
  59.  
  60. /*
  61.  * class basic_ios<charT, traits>
  62.  *
  63.  */
  64.  
  65.  
  66. /*
  67.  *
  68.  *            class basic_ios<charT,traits> member functions   
  69.  *
  70.  */
  71.  
  72.  
  73. /*
  74.  * basic_ios(basic_streambuf *)
  75.  */
  76.  
  77. template<class charT, class traits>
  78. basic_ios<charT, traits>::
  79. basic_ios(basic_streambuf<charT, traits> *sb_arg)
  80. {
  81.   init(sb_arg);
  82. }
  83.  
  84.  
  85. /*
  86.  * ~basic_ios()
  87.  */
  88.  
  89. template<class charT, class traits>
  90. basic_ios<charT, traits>::~basic_ios()
  91. {
  92.  
  93. }
  94.  
  95. /*
  96.  * char_type fill() const
  97.  */
  98.  
  99. template<class charT, class traits>
  100. _TYPENAME basic_ios<charT,traits>::char_type 
  101. basic_ios<charT,traits>::fill() const
  102. {
  103.   return fillch_;
  104. }
  105.  
  106. /*
  107.  * int_type fill(char_type)
  108.  */
  109.  
  110. template<class charT, class traits> 
  111. _TYPENAME basic_ios<charT,traits>::char_type
  112. basic_ios<charT,traits>::fill(char_type ch)
  113. {
  114.   #ifdef _RWSTD_MULTI_THREAD
  115.    _RWSTDGuard guard(this->stream_mutex_);
  116.   #endif
  117.  
  118.   char_type    temp = fillch_;
  119.  
  120.   fillch_ = ch;
  121.  
  122.   return temp;
  123. }
  124.  
  125.  
  126. /*
  127.  * ios_type& copyfmt(const ios_type& )
  128.  */
  129.  
  130. template<class charT, class traits>
  131. basic_ios<charT, traits>&
  132. basic_ios<charT, traits>::
  133. copyfmt(const basic_ios<charT, traits>& rhs)
  134. {
  135.   #ifdef _RWSTD_MULTI_THREAD
  136.    _RWSTDGuard guard(this->stream_mutex_);
  137.   #endif
  138.  
  139.   tiestr_ = rhs.tiestr_;
  140.    
  141.   fillch_ = rhs.fillch_;
  142.  
  143.   ios_base::_RW_UNSAFE_copyfmt( rhs );
  144.  
  145.   except_ = rhs.except_;
  146.  
  147.   return *this;
  148. }
  149.  
  150.  
  151. /*
  152.  * basic_ostream *tie(basic_ostream *)
  153.  */
  154.  
  155. template<class charT, class traits>
  156. basic_ostream<charT, traits> *
  157. basic_ios<charT, traits>::
  158. tie(basic_ostream<charT, traits> *tie_arg)
  159. {
  160.   #ifdef _RWSTD_MULTI_THREAD
  161.    _RWSTDGuard guard(this->stream_mutex_);
  162.   #endif
  163.  
  164.   basic_ostream<charT, traits>   *temp = tiestr_;
  165.   tiestr_ = tie_arg;
  166.   return temp;
  167. }
  168.  
  169.  
  170. /*
  171.  * basic_streambuf *rdbuf(basic_streambuf *)
  172.  */
  173.  
  174. template<class charT, class traits>
  175. _TYPENAME basic_ios<charT, traits>::streambuf_type*    
  176. basic_ios<charT, traits>::                     
  177. rdbuf( basic_streambuf<charT, traits> *sb)
  178. {
  179.   #ifdef _RWSTD_MULTI_THREAD
  180.    _RWSTDGuard guard(this->stream_mutex_);
  181.   #endif
  182.  
  183.   basic_streambuf<charT, traits>   *temp = sb_;
  184.  
  185.   sb_ = sb;
  186.  
  187.   if ( sb==0 ) 
  188.     state_ |= ios_base::badbit;
  189.  
  190.   _RW_UNSAFE_clear();
  191.  
  192.   return temp;
  193. }
  194.  
  195. /*
  196.  * basic_ios()
  197.  */
  198.  
  199. template<class charT, class traits>
  200. basic_ios<charT, traits>::basic_ios()
  201. {
  202.   init(0);
  203. }
  204.  
  205. /*
  206.  * void imbue(const locale& )
  207.  */
  208.  
  209. template<class charT, class traits>
  210. locale basic_ios<charT, traits>::
  211. imbue(const locale& loc)
  212. {
  213.    locale tmp = getloc();
  214.    
  215.    ((ios_base *)(this))->imbue(loc);
  216.    
  217.    if ( rdbuf() )
  218.      rdbuf()->pubimbue(loc);
  219.  
  220.    return tmp;  
  221. }
  222.  
  223.  
  224. /*
  225.  * void init(basic_streambuf *)
  226.  */
  227.  
  228. template<class charT, class traits>
  229. void basic_ios<charT, traits>::
  230. init(basic_streambuf<charT, traits> *sb)
  231. {
  232.   #ifdef _RWSTD_MULTI_THREAD
  233.    _RWSTDGuard guard(this->stream_mutex_);
  234.   #endif
  235.  
  236.   sb_ = sb;
  237.   tiestr_ = 0;
  238.  
  239.   if(sb_)
  240.     state_ = goodbit;
  241.   else
  242.     state_ = badbit;
  243.  
  244.   except_ = goodbit;
  245.   fmtfl_ = skipws | dec;
  246.   wide_ = 0;
  247.   prec_ = 6;
  248.  
  249.   fillch_ = widen(' ');
  250.  
  251.   fmtfl_ &= ~ios_base::adjustfield;
  252.  
  253.   fmtfl_ |= (ios_base::right & ios_base::adjustfield);
  254.  
  255. }
  256.  
  257. #ifdef _RWSTD_MULTI_THREAD
  258.  
  259. /*
  260.  * lock the associated buffer
  261.  */
  262.  
  263.  
  264. template <class charT, class traits>
  265. basic_ios<charT,traits>& lock(basic_ios<charT,traits>& strm)
  266. {
  267.   if ( strm.rdbuf() )
  268.    strm.rdbuf()->_RW_lock_buffer();
  269.  
  270.   return strm;
  271. }
  272.  
  273. template <class charT, class traits>
  274. basic_ios<charT,traits>& unlock(basic_ios<charT,traits>& strm)
  275. {
  276.   if ( strm.rdbuf() )
  277.    strm.rdbuf()->_RW_unlock_buffer();
  278.  
  279.   return strm;
  280. }
  281.  
  282. #endif
  283.  
  284.  
  285. #ifndef _RWSTD_NO_NAMESPACE
  286. }
  287. #endif
  288.  
  289. #pragma option pop
  290. #endif /* __IOS_CC */
  291.